package com.tx.websocket.demo.common;

import lombok.Data;

@Data
public class JsonResult<T> {

    private int code;
    private String message;
    private T t;

    public JsonResult(int code, String message, T t) {
        this.code = code;
        this.message = message;
        this.t = t;
    }

    public static JsonResult errorResult(String message) {
        return new JsonResult<>(1, message, null);
    }

    public static JsonResult errorResult() {
        return new JsonResult<>(1, "ERROR", null);
    }

    public static <T> JsonResult<T> successResult(String message, T t) {
        return new JsonResult<>(0, message, t);
    }

    public static <T> JsonResult<T> successResult(T t) {
        return new JsonResult<>(0, "SUCCESS", t);
    }

    public static JsonResult fatalResult() {
        return new JsonResult<>(999, "FATAL ERROR", null);
    }
}
